//
//  WBStatusCell.swift
//  0829-Weibo
//
//  Created by 毕仲阳 on 16/9/3.
//  Copyright © 2016年 mycompany. All rights reserved.
//

import UIKit
let WBStatusCellMargin : CGFloat = 10

class WBStatusCell: UITableViewCell {
    var statusViewModel:WBStatusViewModel!
    {
        didSet
        {
            originalView.statusViewModel = statusViewModel
            toolBarView.statusViewModel = statusViewModel
            if statusViewModel.status?.retweeted_status != nil{
                
                retweetView.isHidden = false
                retweetView.statusViewModel = statusViewModel
                toolBarView.snp_remakeConstraints(closure: { (make) in
                    make.top.equalTo(self.retweetView.snp_bottom)
                    make.left.right.bottom.equalTo(self.contentView)
                    make.height.equalTo(35)
                })
            }else
            {
               retweetView.isHidden = true
                toolBarView.snp_remakeConstraints(closure: { (make) in
                    make.top.equalTo(self.originalView.snp_bottom)
                    make.left.right.bottom.equalTo(self.contentView)
                    make.height.equalTo(35)
                })
            }
        }
    }
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.setUI()
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setUI() {
        //设置选中的样式
        self.selectionStyle = UITableViewCellSelectionStyle.none
        contentView.backgroundColor = UIColor.lightGray
        //添加子控件
       self.contentView.addSubview(originalView)
        self.contentView.addSubview(retweetView)
        self.contentView.addSubview(toolBarView)
        
        //布局子控件
        originalView.snp_makeConstraints { (make)->Void in
            //make.top.left.right.equalTo(self.contentView).offset(WBStatusCellMargin)
            make.top.equalTo(self.contentView).offset(WBStatusCellMargin)
            make.left.right.equalTo(self.contentView)
            //make.bottom.equalTo(self.contentView)
        }
        retweetView.snp_makeConstraints { (make)->Void in
            make.left.right.equalTo(originalView)
            make.top.equalTo(originalView.snp_bottom)
        }
        toolBarView.snp_makeConstraints { (make)->Void in
            make.top.equalTo(self.retweetView.snp_bottom)
            make.left.right.bottom.equalTo(self.contentView)
            make.height.equalTo(35)
        }
    }
    
    //懒加载控件
    lazy var originalView : WBOriginalStatusView = WBOriginalStatusView()
    lazy var toolBarView : WBToolBarView = WBToolBarView()
    lazy var retweetView : WBRetweetView = WBRetweetView()
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
